package com.tjetc.test.service.impl;

import com.tjetc.test.common.PageResult;
import com.tjetc.test.entity.User;
import com.tjetc.test.mapper.UserMapper;
import com.tjetc.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/9
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean addUser(User user) {
        userMapper.insertUser(user);
        return true;
    }

    @Override
    public User getUserById(int id) {
       return userMapper.selectUserById(id);
    }

    @Override
    public PageResult<List<User>> getPagerUser(String name) {
        // 查询数据
        List<User> users = userMapper.selectUserByName(name);
        // 查询总个数
        int count = userMapper.selectUserTotalCountByName(name);

        PageResult<List<User>> pageResult = new PageResult<>(1, 3, count, users);
        return pageResult;
    }


}